BEGIN{
    if(!Outfile) {
        print "usage: awk -f guid_lasttime_update.awk -v Outfile=value file ...";
        exit;
    }

    Time_begin = systime();
    print strftime("%Y-%m-%d %T",Time_begin) " Starting...";
}

{
    lasttime = ios8601Totimestamp($1,ltTime);
    #print "db.clientUser.update({\"guid\":\""$2"\"},{$set:{\"lasttime\":"lasttime"}})" >> Outfile;
    print "\""$2"\""",""\""$3"\""",""\""lasttime"\"" >> Outfile
}

END{
    if(Time_begin){
        Time_end = systime();
        print strftime("%Y-%m-%d %T",Time_end) " End";
        print "Take Time: " Time_end - Time_begin "s";
        print "Row Total: " NR "\n";
    }
}

# time_iso8601 to unix timestamp
function ios8601Totimestamp(timeStr,reTime) {
    gsub(/[\42T\-:]/," ",timeStr);
    split(timeStr,reTime,"+");
    return mktime(reTime[1]);
}
